package cn.oms.file.provider.security;

import cn.oms.file.provider.interceptor.AuthInterceptor;
import cn.oms.file.provider.interceptor.DemoInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//使用SpringMvc框架功能配置跨域
@Configuration
public class WebConfig implements WebMvcConfigurer {

    // 跨域问题
    @Override
    public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedOrigins("*")
                    .allowedMethods("*")
                    .allowedHeaders("*");
    }
    //配置拦截器
    @Autowired
    private DemoInterceptor demoInterceptor;
    @Autowired
    private AuthInterceptor authInterceptor;
    //设置拦截器生效路径
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(demoInterceptor)
                //这个哪些路径经过这个拦截器
                .addPathPatterns("");
//        registry.addInterceptor(authInterceptor)
//                .addPathPatterns(
//                        "/file/excel"
////                        "/v1/users/me"
//                );
    }
}
